﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VirtualPedal;

namespace VPApp
{
	/// <summary>
	/// Interaction logic for FloatTweaker.xaml
	/// </summary>
	public partial class FloatTweaker : UserControl
	{
		TweakablePropertyInfo m_PropertyInfo;
		PedalBase m_Pedal;

		public FloatTweaker()
		{
			InitializeComponent();
		}

		public FloatTweaker(PedalBase pedal, TweakablePropertyInfo propInfo)
		{
			m_Pedal = pedal;
			m_PropertyInfo = propInfo;
			InitializeComponent();
			var textBlock = new TextBlock();
			textBlock.Text = propInfo.Name;
			textBlock.TextTrimming = TextTrimming.CharacterEllipsis;
			textBlock.MaxWidth = 52;
			label1.Content = textBlock;
			slider1.ValueChanged += new RoutedPropertyChangedEventHandler<double>(slider1_ValueChanged);
			slider1.Minimum = propInfo.MinValue;
			slider1.Maximum = propInfo.MaxValue;
			slider1.Value = propInfo.DefaultValue;
			slider1.TickFrequency = (propInfo.MaxValue - propInfo.MinValue) / 10;
			slider1.SmallChange = slider1.TickFrequency / 5;
		}

		void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			textBox1.Text = string.Format("{0:f2}", e.NewValue);
			m_PropertyInfo.SetValue(m_Pedal, (float)e.NewValue);
		}
	}
}